package leetcode;

//1945. 字符串转化后的各位数字之和
public class ques_1945 {
    public static int getLucky(String s, int k) {
        StringBuffer target=new StringBuffer();//构造初步字符串(字母转化为数字)
        for(int i=0;i<s.length();i++){
            char ch=s.charAt(i);
            target.append((int)ch-96);
        }
        String intString=target.toString();
        while(k>0){
            intString=sumAt(intString);
            k--;
        }

        return Integer.parseInt(intString);
    }

    //将数字字符串进行重复每一位求和并重组为新的数字字符串
    public static String sumAt(String intString){
        int sum=0;
        for(int i=0;i<intString.length();i++){
            char ch=intString.charAt(i);
            sum+=Integer.parseInt(ch+"");
        }
        return sum+"";
    }

    public static void main(String[] args) {
        System.out.println(getLucky("hvmhoasabaymnmsd",1));
    }
}
